package com.mdd.admin.controller.client;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IClientCrmHighseasService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.ClientCrmHighseasCreateValidate;
import com.mdd.admin.validate.ClientCrmHighseasUpdateValidate;
import com.mdd.admin.validate.ClientCrmHighseasSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.ClientCrmHighseasListedVo;
import com.mdd.admin.vo.ClientCrmHighseasDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/highseas")
@Api(tags = "客户公海管理")
public class ClientCrmHighseasController {

    @Resource
    IClientCrmHighseasService iClientCrmHighseasService;

    @GetMapping("/list")
    @ApiOperation(value="客户公海列表")
    public AjaxResult<PageResult<ClientCrmHighseasListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated ClientCrmHighseasSearchValidate searchValidate) {
        PageResult<ClientCrmHighseasListedVo> list = iClientCrmHighseasService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="客户公海详情")
    public AjaxResult<ClientCrmHighseasDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        ClientCrmHighseasDetailVo detail = iClientCrmHighseasService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "客户公海新增")
    @PostMapping("/add")
    @ApiOperation(value="客户公海新增")
    public AjaxResult<Object> add(@Validated @RequestBody ClientCrmHighseasCreateValidate createValidate) {
        iClientCrmHighseasService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户公海编辑")
    @PostMapping("/edit")
    @ApiOperation(value="客户公海编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody ClientCrmHighseasUpdateValidate updateValidate) {
        iClientCrmHighseasService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户公海删除")
    @PostMapping("/del")
    @ApiOperation(value="客户公海删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iClientCrmHighseasService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
